import request from "@/utils/request";
import { ProjectCompletedEditForm, ProjectCompletedAuditForm } from "./types";

const currentSystem = localStorage.getItem("usertypeName");

/**
 * 获取完工申请列表(分页)
 *
 * @param id
 */
export function QueryProjectCompletedList(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/completed/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/completed/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/completed/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/completed/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/completed/page`;
      break;
    default:
      url = `/api/v1/manager/completed/page`;
  }
  return request({
    url: url,
    method: "GET",
    params: data,
  });
}

/**
 * 新增完工申请
 *
 * @param id
 */
export function AddProjectCompleted(data: ProjectCompletedEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/completed/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/completed/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/completed/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/completed/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/completed/create`;
      break;
    default:
      url = `/api/v1/manager/completed/create`;
  }
  return request({
    url: url,
    method: "POST",
    data: data,
  });
}

/**
 * 修改完工申请
 *
 * @param id
 */
export function UpdateProjectCompleted(data: ProjectCompletedEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/completed/update`;
      break;
    case "Corp":
      url = `/api/v1/corp/completed/update`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/completed/update`;
      break;
    case "Manager":
      url = `/api/v1/manager/completed/update`;
      break;
    case "Commander":
      url = `/api/v1/commander/completed/update`;
      break;
    default:
      url = `/api/v1/manager/completed/update`;
  }
  return request({
    url: url+`/${data.id}`,
    method: "put",
    data: data,
  });
}
/**
 * 获取完工申请详情
 *
 * @param id
 */

export function GetProjectCompletedForm(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/completed/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/completed/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/completed/${id}`;

      break;
    case "Manager":
      url = `/api/v1/manager/completed/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/completed/${id}`;
      break;
    default:
      url = `/api/v1/manager/completed/${id}`;
  }
  return request({
    url: url,
    method: "GET",
  });
}

/**
 * 审核完工申请
 *
 * @param id
 */
export function AuditProjectCompleted(data: ProjectCompletedAuditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/completed/audit`;
      break;
    case "Corp":
      url = `/api/v1/corp/completed/audit`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/completed/audit`;
      break;
    case "Manager":
      url = `/api/v1/manager/completed/audit`;
      break;
    case "Commander":
      url = `/api/v1/commander/completed/audit`;
      break;
    default:
      url = `/api/v1/manager/completed/audit`;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 删除完工申请
 */
export function DeleteProjectCompleted(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/completed/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/completed/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/completed/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/completed/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/completed/${id}`;
      break;
    default:
      url = `/api/v1/manager/completed/${id}`;
  }
  return request({
    url: url,
    method: "delete",
  });
}
